package com.eway.esb.service.rest.patient;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import org.mule.api.MuleMessage;
import org.mule.module.client.MuleClient;

import com.eway.esb.service.rest.RestServiceSupport;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

@Path("/patient")
public class PatientService extends RestServiceSupport{
	
	//根据ID查询医生
	@POST
	@Produces("text/plain")
	@Path("/searchDoctorInfoById")
	public String searchDoctorInfoById(@FormParam("cctj") String cctj,@FormParam("unitCode") String unitCode){
		System.out.println("searchDoctorInfoById-------------lsh="+cctj+"unitCode="+unitCode);
		cctj = cctj==null?"":cctj.trim();
		unitCode=unitCode==null?"020sfy":unitCode.trim();
		List<DoctorDTO> returnList = new ArrayList<DoctorDTO>();
       
		try{
			Map insertMap = new HashMap();
			if(unitCode.equalsIgnoreCase("020nfy"))
			{
				insertMap.put("cctj", cctj); 
		        MuleClient client = new MuleClient();  
		        MuleMessage response = client.send("vm://nfySearchDoctorInfo", insertMap, null);
		        List<Map> list=(List)response.getPayload();
		        for (Map objmap : list) {
					String lshs = (String) objmap.get("emp_no");
					String xm = (String) objmap.get("name");
					System.out.println("xm原值...."+xm);
					xm=new String(xm.toString().getBytes("ISO-8859-1"),"GBK"); 
					System.out.println("xm转换后的值[new String(xm.toString().getBytes('ISO-8859-1'),'GBK')]...." +xm);
					DoctorDTO doctorDTO = new DoctorDTO();
					doctorDTO.setLsh(lshs);
					doctorDTO.setXm(xm);
					doctorDTO.setXb("暂无数据");
					doctorDTO.setXx("暂无数据");
					doctorDTO.setAge("暂无数据");
					doctorDTO.setDept("暂无数据");
					doctorDTO.setResume("暂无数据");
					doctorDTO.setSpecia("暂无数据");
					doctorDTO.setTitle("暂无数据");
					returnList.add(doctorDTO);
				}
			}
				
			
		}catch(Exception e){
			e.printStackTrace();
		}
		Gson gson = new Gson();
		Type type = new TypeToken<List<DoctorDTO>>() {}.getType();
		String returnStr=gson.toJson(returnList,type);
        return returnStr;
	}
}
